package org.mspring.mlog.service;

import java.util.Date;
import org.mspring.mlog.dao.TwitterDao;
import org.mspring.mlog.entity.Twitter;
import org.mspring.platform.dao.Page;
import org.mspring.platform.dao.query.QueryBuilder;
import org.mspring.platform.security.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 * @author Gao Youbo
 * @since 2013-5-24
 */
@Service
public class TwitterService {

    @Autowired
    private TwitterDao twitterDao;

    public Twitter findById(long id) {
        return twitterDao.findById(id);
    }

    public Page<Twitter> listPage(QueryBuilder queryBuilder, Page<Twitter> page) {
        return twitterDao.listPage(queryBuilder, page);
    }

    @Transactional
    public void delete(Long... ids) {
        twitterDao.delete(ids);
    }

    @Transactional
    public Long create(Twitter twitter) {
        twitter.setCreateTime(new Date());
        if (twitter.getAuthor() == null) {
            twitter.setAuthor(SecurityUtils.getCurrentUser());
        }
        return twitterDao.create(twitter);
    }
}
